package com.eleven.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.eleven.dao.ProjectsMapper;
import com.eleven.pojo.Projects;
import com.eleven.pojo.ProjectsExample;
import com.eleven.service.ProjectsReceptionService;

import net.sf.jsqlparser.statement.select.Select;
@Service
public class ProjectsReceptionServiceImpl implements ProjectsReceptionService {
	@Autowired
	ProjectsMapper projectsMapper;
	//获取每种公益类型下众筹中的项目详情信息
	public List<Projects> getProjectsGylxZcz(Integer pstId) {
		ProjectsExample example = new ProjectsExample();
		example.createCriteria().andPsPstIdEqualTo(pstId).andPsTypeEqualTo(2);
		List<Projects> list = projectsMapper.selectByExample(example);
		return list;
	}
	//获取即将上线和众筹成功的项目信息
	public List<Projects> getProjectsType(Integer type) {
		ProjectsExample example = new ProjectsExample();
		example.createCriteria().andPsTypeEqualTo(type);
		List<Projects> list = projectsMapper.selectByExample(example);
		return list;
	}
	//获取公益类型下的项目详情信息
	public List<Projects> getGylxprojects(Integer pstId,Integer zmztValue,Integer xmpxValue) {
		ProjectsExample example = new ProjectsExample();
		List<Projects> list =null;
		if (pstId==0) {
			if (zmztValue==4) {
				pxJudge(example, zmztValue, xmpxValue);
				list = projectsMapper.selectxmjxps(example);
			}else {
				if (zmztValue==0) {
					pxJudge(example, zmztValue, xmpxValue);
					example.createCriteria().andPsTypeNotEqualTo(0)
					.andPsTypeNotEqualTo(4).andPsTypeNotEqualTo(5);
				}else {
					pxJudge(example, zmztValue, xmpxValue);
					example.createCriteria().andPsTypeNotEqualTo(0)
					.andPsTypeNotEqualTo(4).andPsTypeNotEqualTo(5).andPsTypeEqualTo(zmztValue);
				}
				list = projectsMapper.selectByExample(example);
			}
		}else {
			if (zmztValue==4) {
				pxJudge(example, zmztValue, xmpxValue);
				list = projectsMapper.selectxmjxps(example);
			}else {
				if(zmztValue==0) {
					pxJudge(example, zmztValue, xmpxValue);
					example.createCriteria().andPsPstIdEqualTo(pstId).andPsTypeNotEqualTo(0)
					.andPsTypeNotEqualTo(4).andPsTypeNotEqualTo(5);
				}else {
					pxJudge(example, zmztValue, xmpxValue);
					example.createCriteria().andPsPstIdEqualTo(pstId).andPsTypeNotEqualTo(0)
					.andPsTypeNotEqualTo(4).andPsTypeNotEqualTo(5).andPsTypeEqualTo(zmztValue);
				}
				list = projectsMapper.selectByExample(example);
			}
		}
		
		return list;
	}
	//用来判断执行那种排序
	public void pxJudge(ProjectsExample example,Integer zmztValue,Integer xmpxValue) {
		if(xmpxValue==1) {
			example.setOrderByClause("DATEDIFF(now(),ps_starttime) asc");
		}
		if(xmpxValue==2){
			example.setOrderByClause("ps_getmoney desc");
		}
		if(xmpxValue==3) {
			example.setOrderByClause("ps_getpeople desc");
		}
		if (zmztValue !=3 || zmztValue!=4) {
			if(xmpxValue==4) {
				example.setOrderByClause("DATEDIFF(ps_endtime,now()) asc");
			}
		}
	}
}
